package com.test.group.plugin.demo.toolWindow;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.*;
import com.intellij.ui.content.ContentManager;
import com.test.group.plugin.demo.toolWindow.panel.MyPanel;
import org.jetbrains.annotations.NotNull;

/**
 * 自己工具窗口的工厂类
 * Nothing can be injected as it runs in the root pico container.
 * @author tianfeng
 */
public class MyToolWindowFactory implements ToolWindowFactory {

  @Override
  public void createToolWindowContent(Project project, final ToolWindow toolWindow) {
    var contentManager = toolWindow.getContentManager();
    // 添加标签页
    addMyTab(project, contentManager);

    toolWindow.setType(ToolWindowType.DOCKED, null);
  }

  private static void addMyTab(Project project, @NotNull ContentManager contentManager) {
    var myPanel = new MyPanel(project);
    var currentFileContent = contentManager.getFactory()
            .createContent(
                    myPanel,
                    "自己的名字",
                    false);
    // 是否可以关闭
    currentFileContent.setCloseable(false);
    contentManager.addDataProvider(myPanel);
    contentManager.addContent(currentFileContent);
  }

}
